{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<a href=\"https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-opencv\" target=\"_blank\"><img align=\"left\" src=\"data/cover.jpg\" style=\"width: 76px; height: 100px; background: white; padding: 1px; border: 1px solid black; margin-right:10px;\"></a>\n",
    "*This notebook contains an excerpt from the book [Machine Learning for OpenCV](https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-opencv) by Michael Beyeler.\n",
    "The code is released under the [MIT license](https://opensource.org/licenses/MIT),\n",
    "and is available on [GitHub](https://github.com/mbeyeler/opencv-machine-learning).*\n",
    "\n",
    "*Note that this excerpt contains only the raw code - the book is rich with additional explanations and illustrations.\n",
    "If you find this content useful, please consider supporting the work by\n",
    "[buying the book](https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-opencv)!*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Classifying handwritten digits using k-means](08.03-Classifying-Handwritten-Digits-Using-k-Means.ipynb) | [Contents](../README.md) | [9. Using Deep Learning to Classify Handwritten Digits](09.00-Using-Deep-Learning-to-Classify-Handwritten-Digits.ipynb) >"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Implementing Agglomerative Hierarchical Clustering\n",
    "\n",
    "Although OpenCV does not provide an implementation of agglomerative hierarchical\n",
    "clustering, it is a popular algorithm that should, by all means, belong to our machine\n",
    "learning repertoire.\n",
    "\n",
    "We start out by generating 10 random data points, just like in the previous figure:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "from sklearn.datasets import make_blobs\n",
    "X, y = make_blobs(n_samples=10, random_state=100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the familiar statistical modeling API, we import the `AgglomerativeClustering`\n",
    "algorithm and specify the desired number of clusters:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "from sklearn import cluster\n",
    "agg = cluster.AgglomerativeClustering(n_clusters=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Fitting the model to the data works, as usual, via the `fit_predict` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "labels = agg.fit_predict(X)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can generate a scatter plot where every data point is colored according to the predicted\n",
    "label:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x23811a45908>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlwAAAF0CAYAAAD2C+d2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHolJREFUeJzt3XtwnPV56PFndbNkW5Ys344vGBvLhFgFA7F9EggOBk5p\nOSY1KdHh0iZk4nYCpmGStgPUSaBjXCCBUqg7zgQopAO0MQkwkJJCwuWQQDgYMMXI4eI0xoChNpIv\nsmRZlrTnD4qCq/Vdv9219PnMZJLdfaV95smM/NW+q30z2Ww2GwAAJFNS6AEAAAY6wQUAkJjgAgBI\nTHABACQmuAAAEhNcAACJlfXHN1m+fHm8+OKLUVNTEzfccENERGzfvj3+7u/+LjZt2hRjx46Nr33t\nazF06ND+eDoAgMNKv7zCNW/evFi8ePFu9z3wwANx7LHHxs033xwND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+evEj7jgggt6/7hkzZo18dBD\nD+0xtiKK6JPmP3oh7GHDhvVeCPu+++6LBx54IMaPH9/7EvjixYsHzZuA97SXiA8+FuLxxx+PsrKy\nQfuxEK+99lrccccd0dPTE+Xl5bFw4cKYOnVqoccquK6urli+fHmsW7cuysvL4wtf+ELMmDGj0GMV\nlUsvvTSuu+46wRURX/3qV6Orq6s3yqdPnx4LFy4s8FSF8dJLL8Udd9wR2Ww2TjvtNB8LER+8knPV\nVVfF5MmTI5PJRCaTifPPPz+OP/74Qo9WND4Mrr19LETRBBcAwEBVNB8LAQAwUAkuAIDEBBcAQGKC\nCwAgMcEFAJCY4AIASExwAQAkJrgAABL7/243JgHeVd8jAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2380ff52438>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "plt.style.use('ggplot')\n",
    "plt.figure(figsize=(10, 6))\n",
    "plt.scatter(X[:, 0], X[:, 1], c=labels, s=100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "That's it! This marks the end of another wonderful adventure."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Classifying handwritten digits using k-means](08.03-Classifying-Handwritten-Digits-Using-k-Means.ipynb) | [Contents](../README.md) | [9. Using Deep Learning to Classify Handwritten Digits](09.00-Using-Deep-Learning-to-Classify-Handwritten-Digits.ipynb) >"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
